
Imports System.Drawing
Imports System.Drawing.Text
Imports System.Drawing.Drawing2D
Imports System.Drawing.Font

Public Class Camino
    Public distancia As Integer
    Public tipo As Integer
    Public origen As Point
    Public destino As Point
    Public Shared caminos As New ArrayList
    Dim lapizTierra As New Pen(Color.Brown, 5)
    Dim lapizRuta As New Pen(Color.Gray, 5)
    Dim lapizAutoPista As New Pen(Color.Blue, 5)
    Private fuente As New Font("Times New Roman", 15, FontStyle.Bold, GraphicsUnit.Pixel)
    Private string_format As New StringFormat
    Dim rect As Rectangle
    Dim puntoMedio As Point

    Public Sub New(ByVal origen As Point, ByVal destino As Point, ByVal tipo As Integer, ByVal distancia As Integer)
        Me.origen = origen
        Me.destino = destino
        Me.tipo = tipo
        Me.distancia = distancia
    End Sub

    Public Sub dibujarDistancias(ByVal gr As Graphics)
        Me.puntoMedio = Me.obtenerPuntoMedio(Me.origen, Me.destino)
        Me.rect = figuras.DameRec(Me.puntoMedio, 15, 15)
        Me.string_format.Alignment = StringAlignment.Center
        Me.string_format.LineAlignment = StringAlignment.Center
        gr.DrawString(Me.distancia.ToString, Me.fuente, Brushes.Black, Me.rect, Me.string_format)
    End Sub

    Public Sub dibujar(ByVal gr As Graphics)
        Select Case Me.tipo
            Case 1
                gr.DrawLine(Me.lapizTierra, Me.origen, Me.destino)
            Case 5
                gr.DrawLine(Me.lapizRuta, Me.origen, Me.destino)
            Case Else
                gr.DrawLine(Me.lapizAutoPista, Me.origen, Me.destino)
        End Select
    End Sub

    Public Function obtenerPuntoMedio(ByVal p1 As Point, ByVal p2 As Point)
        Dim X As Single
        Dim Y As Single

        X = (p1.X + p2.X) / 2
        Y = (p1.Y + p2.Y) / 2

        Return New Point(X, Y)
    End Function

    Public Shared Sub crearCaminos(ByVal matrizCaminos As Array)
        Dim i, j As Integer
        Dim cam As Camino
        Camino.caminos.Clear()

        For i = 0 To matrizCaminos.GetUpperBound(0)
            For j = 0 To matrizCaminos.GetUpperBound(1)
                If (matrizCaminos(i, j, 0) <> 0) Then
                    Try
                        cam = New Camino(PuntosEstaticos.puntos(i), PuntosEstaticos.puntos(j), matrizCaminos(i, j, 1), matrizCaminos(i, j, 0))
                        Camino.caminos.Add(cam)
                    Catch
                    End Try
                End If
            Next
        Next
    End Sub

End Class
